#include "http_cgi_handler.h"
//#include "BSP_TC_Flash.h"      // 你的 Flash 操作函数声明
#include "socket.h"            // W5500 socket 状态函数，如 getSn_SR()
#include <stdio.h>

// 获取网络配置信息
int user_handle_get_netinfo(uint8_t* buf)
{
    //NetCfg_TypeDef netCfg;
    //BSP_TC_Flash_ReadNetCfg(&netCfg);  // 读取网络配置结构体-初始化时从flash读取到全局变量中

		
		
		return sprintf((char*) buf,
					"NetinfoCallback({\"mac\":\"%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\",\
											\"ip\":\"%d.%d.%d.%d\",\
											\"gw\":\"%d.%d.%d.%d\",\
											\"sn\":\"%d.%d.%d.%d\",\
											\"dns\":\"%d.%d.%d.%d\",\
											\"dhcp\":\"%d\"\
											});",
					local_net_config.auch_SHA[0],local_net_config.auch_SHA[1], local_net_config.auch_SHA[2], 
			    local_net_config.auch_SHA[3],local_net_config.auch_SHA[4], local_net_config.auch_SHA[5],
					local_net_config.auch_SIP[0],local_net_config.auch_SIP[1], local_net_config.auch_SIP[2], local_net_config.auch_SIP[3],
					local_net_config.auch_GA[0], local_net_config.auch_GA[1],  local_net_config.auch_GA[2],  local_net_config.auch_GA[3],
					local_net_config.auch_SUB[0],local_net_config.auch_SUB[1], local_net_config.auch_SUB[2], local_net_config.auch_SUB[3],
					local_net_config.auch_DNS[0],local_net_config.auch_DNS[1], local_net_config.auch_DNS[2], local_net_config.auch_DNS[3],
					0x00
					);
}

// 获取 Socket 状态信息（以 Socket 0 为例）
int user_handle_get_socketinfo(uint8_t* buf)
{
    uint8_t sock_status = getSn_SR(0);  // 获取 Socket 0 状态   
	
    return sprintf((char*)buf, "Socket0_Status=0x%02X\r\n", sock_status);
}
